
$(function(){
	$("#address").click(function(){
		$.ajax({
			type:"POST",
			url:"SystemConfig",
			data:"method=0",
			dataType:"json",
			contentType:"application/x-www-form-urlencoded; charset=utf-8",
			success:function(data){
				var src = "<option value='0'>选择一个部门</option>";
				for(var count in data){
					src += "<option value='"+data[count].id+"'>"+data[count].departmentName+"</option>";
				}
				$("#select").html(src);
			},
			error:function(data){
				alert("error:"+data);
			}
		});
	});
	$(".shouru").each(function(i,e){
		getInt($(e).html(),e)
	});
	
	function getInt(values,e){
		var flag = values.indexOf(".");
		var tempvalue = values;
		if(flag > 0){
			tempvalue = values.substring(0,flag);
		}
		var len = tempvalue.length;
		var startposition = 0;
		var position = len % 3;
		var newValue = "";
		
		while(startposition<(len+1)){
			if(position == 0){
				startposition = position;
				position += 3;
			}else if(position >= len){
				newValue += tempvalue.substring(startposition,position);
				startposition = position;
				position += 3;
			}else{
				newValue += tempvalue.substring(startposition,position)+",";
				startposition = position;
				position += 3;
			}
			
		}
		newValue += values.substring(flag,values.length)
		$(e).html("$ "+newValue);
	}
});

$(function(){
	$("#btnCreate").click(function(){
		var departmentId = $("#select").val();
		var businessDate = $("#Bussiness").val();
		var lastString = $("#Last").val();
		var text1String = $("#Text1").val();
		$.ajax({
			type:"POST",
			url:"SystemConfig",
			dataType:"json",
			contentType:"application/x-www-form-urlencoded; charset=utf-8",
			async:false,
//			data:{
//				method=1
//				departmentId:departmentId,
//				bussinessString:bussinessString,
//				lastString:lastString,
//				text1String:text1String
//			},
			data:"method=1&departmentId="+departmentId+"&businessDate="+businessDate+"&lastString="+lastString+"&text1String="+text1String,
			success:function(data){
				location.reload();
				alert("添加成功");
			},
			error:function(){
				alert("添加失败");
			}
		});
		
	});
	$("#btnReset").click(function(){
		$("#select").val("0");
		$("#Bussiness").val("");
		$("#Last").val("");
		$("#Text1").val("");
	});
});

$(function(){
	$(".alterIncome").click(function(){
		var incomeId = $(this).parent().prev().prev().prev().prev().attr("incomeId");
		$("#Name1").val($(this).parent().prev().prev().prev().prev().html());
		$("#Bussiness1").val($(this).parent().prev().prev().prev().html());
		$("#Last1").val($(this).parent().prev().prev().html());
		$("#Text2").val($(this).parent().prev().html());
		$("#btnUpdate").click(function(){
			var departmentName = $("#Name1").val();
			var lastString = $("#Last1").val();
			var text1String = $("#Text2").val();
			$.ajax({
				type:"POST",
				url:"SystemConfig",
				dataType:"json",
				contentType:"application/x-www-form-urlencoded; charset=utf-8",
				async:false,
				data:"method=4&departmentName="+departmentName+"&lastString="+lastString+"&text1String="+text1String+"&incomeId="+incomeId,
				success:function(data){
					location.reload();
					alert("修改成功");
				},
				error:function(){
					alert("修改失败");
				}
			});
		});
	});
	$("#btnReset1").click(function(){
		$("#Name1").val("");
		$("#Last1").val("");
		$("#Text2").val("");
	});
});
